package com.paishen.dbgenerator;


import de.greenrobot.daogenerator.DaoGenerator;
import de.greenrobot.daogenerator.Entity;
import de.greenrobot.daogenerator.Property;
import de.greenrobot.daogenerator.PropertyType;
import de.greenrobot.daogenerator.Schema;

public final class DBCreator {
    private static final String TARGET_PACKAGE = "com.paishen.peiniwan.database";
    private static final String TARGET_PATH = "D:\\android\\StudioProjects\\peiniwan\\app\\src\\main\\java";

    public static void main(String[] args) throws Exception {
         createDB_version1();
    }

    private static void createDB_version1() throws Exception {
        Schema schema = new Schema(2016040801, TARGET_PACKAGE);

        Entity user = schema.addEntity("User");
        user.addIdProperty();
        user.addProperty(PropertyType.String, "phone");
        user.addProperty(PropertyType.String, "password");
        user.addProperty(PropertyType.String, "easemob_username");
        user.addProperty(PropertyType.String, "easemob_password");
        user.addProperty(PropertyType.String, "head_img_url");
        user.addProperty(PropertyType.String, "head_img_url_max");
        user.addProperty(PropertyType.String, "nickname");
        user.addProperty(PropertyType.Boolean, "gender");
        user.addProperty(PropertyType.String, "intro");
        // user.addProperty(PropertyType.Boolean, "is_realname");
        user.addProperty(PropertyType.String, "tags");
        user.addProperty(PropertyType.Boolean, "is_verified");
        user.addProperty(PropertyType.Float, "good_rate");
        user.addProperty(PropertyType.Int, "concern");
        user.addProperty(PropertyType.Int, "fans");
        // user.addProperty(PropertyType.Int, "zan_count");
        user.addProperty(PropertyType.String, "height");
        user.addProperty(PropertyType.String, "weight");
        user.addProperty(PropertyType.String, "age");
        user.addProperty(PropertyType.String, "degree");
        user.addProperty(PropertyType.String, "constellation");
        user.addProperty(PropertyType.String, "salary");

        // user.addProperty(PropertyType.String, "affective");
        user.addProperty(PropertyType.String, "profession");
        user.addProperty(PropertyType.String, "city");
        user.addProperty(PropertyType.Float, "amount");
        user.addProperty(PropertyType.Boolean, "app_auto_login");

        user.addProperty(PropertyType.Int, "gift1");
        user.addProperty(PropertyType.Int, "gift5");
        user.addProperty(PropertyType.Int, "gift10");

        Entity coupon = schema.addEntity("Coupon");
        coupon.addIdProperty();
        coupon.addProperty(PropertyType.String, "code").notNull();
        coupon.addProperty(PropertyType.Float, "amount").notNull();
        coupon.addProperty(PropertyType.Boolean, "is_valid").notNull();
        coupon.addProperty(PropertyType.String, "valid_from").notNull();
        coupon.addProperty(PropertyType.String, "valid_to").notNull();
        Property couponUserIdProperty = coupon.addProperty(PropertyType.Long, "userId").notNull().getProperty();
        coupon.addToOne(user, couponUserIdProperty);


        Entity photo = schema.addEntity("Photo");
        photo.addIdProperty();
        photo.addProperty(PropertyType.String, "photo_url").notNull();
        photo.addProperty(PropertyType.String, "created_date").notNull();
        Property photoUserIdProperty = photo.addProperty(PropertyType.Long, "userId").notNull().getProperty();
        photo.addToOne(user, photoUserIdProperty);

        Entity authInfo = schema.addEntity("AuthInfo");
        authInfo.addIdProperty();
        authInfo.addProperty(PropertyType.String, "real_photo");
        authInfo.addProperty(PropertyType.String, "created_date");
        authInfo.addProperty(PropertyType.String, "status").notNull();
        authInfo.addProperty(PropertyType.String, "note");
        Property authInfoUserIdProperty = authInfo.addProperty(PropertyType.Long, "userId").notNull().getProperty();
        authInfo.addToOne(user, authInfoUserIdProperty);


        Entity gift = schema.addEntity("Gift");
        gift.addIdProperty();
        gift.addProperty(PropertyType.String, "title").notNull();
        gift.addProperty(PropertyType.Float, "price").notNull();
        gift.addProperty(PropertyType.String, "image").notNull();

        new DaoGenerator().generateAll(schema, TARGET_PATH);
    }
}
